package com.tws.pctask.controller;

import com.tws.common.enums.ResultEnum;
import com.tws.common.model.ResponseWrapper;
import com.tws.pctask.model.registerManageModel.CheckEmailParam;
import com.tws.pctask.model.registerManageModel.CheckNameParam;
import com.tws.pctask.model.registerManageModel.GetEmailCodeParam;
import com.tws.pctask.model.registerManageModel.RegisterUserParam;
import com.tws.pctask.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description： 注册控制层
 * @Author: wbf
 * @Date: 2022/1/18 14:29
 */
@RestController
@RequestMapping("common/registerManage")
public class RegisterController {
    @Autowired
    RegisterService registerService;
    /**
     * 获取邮箱验证码
     * @param param 邮箱
     * @return 验证码
     */
    @PostMapping("getEmailCode")
    public ResponseWrapper getEmailCode(@Validated GetEmailCodeParam param){
        //字符串判空
        if(param.getUserEmail() == null || param.getUserEmail().equals("")) {
            return ResponseWrapper.markError(ResultEnum.PARAMS_ERROR);
        }
        return registerService.getEmailCode(param);
    }

    /**
     * 2.2检查用户名是否重复
     * @param param 用户名
     * @return true为重复 false为不重复
     */
    @GetMapping("checkName")
    public ResponseWrapper checkName(@Validated CheckNameParam param){
        return registerService.checkName(param);
    }

    /**
     * 2.3检查邮箱是否重复
     * @param param 邮箱
     * @return true为重复 false为不重复
     */
    @GetMapping("checkEmail")
    public ResponseWrapper checkEmail(CheckEmailParam param){
        return registerService.checkEmail(param);
    }

    /**
     * 2.4注册用户
     * @param param 注册参数
     * @return 注册结果
     */
    @PostMapping("registerUser")
    public ResponseWrapper registerUser(@Validated RegisterUserParam param){
        //字符串判空
        if(param.getUserEmail() == null || param.getUserEmail().equals("")) {
            return ResponseWrapper.markError(ResultEnum.PARAMS_ERROR);
        }
        return registerService.registerUser(param);
    }

}
